package cloud.lysky.java.on.async.completable_future;

/**
 * @author luoly
 * @describe
 * @date 2022-08-25 10:12
 **/
public class PriceFinderApp {
    public static void main(String[] args) {
        System.out.println("Processors Count:" + Runtime.getRuntime().availableProcessors());
        BestPriceFinder finder = new BestPriceFinder();
        System.out.println("------------stream------------");
        long start = System.nanoTime();
        System.out.println(finder.findPrices("One Plus 8T"));
        long duration = (System.nanoTime() - start) / 1_000_000;
        System.out.println("Done in " + duration + "msecs");

        System.out.println("------------parallelStream------------");
        start = System.nanoTime();
        System.out.println(finder.findPricesParallel("One Plus 8T"));
        duration = (System.nanoTime() - start) / 1_000_000;
        System.out.println("Done in " + duration + "msecs");

        System.out.println("------------completableFuture------------");
        start = System.nanoTime();
        System.out.println(finder.findPricesCompletableFuture("One Plus 8T"));
        duration = (System.nanoTime() - start) / 1_000_000;
        System.out.println("Done in " + duration + "msecs");

        System.out.println("------------completableFutureWithCustomExecutor------------");
        start = System.nanoTime();
        System.out.println(finder.findPricesCompletableFutureWithCustomExecutor("One Plus 8T"));
        duration = (System.nanoTime() - start) / 1_000_000;
        System.out.println("Done in " + duration + "msecs");
    }
}